//
//  UIBarBurron+Button.swift
//  WB01
//
//  Created by HOP on 15/12/20.
//  Copyright © 2015年 HOP. All rights reserved.
//

import UIKit
// 扩展UIBarButtonItem
extension UIBarButtonItem {

    convenience init(imageName: String) {
        let highlightedImageName = imageName + "_highlighted"
        // 右边按钮
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: highlightedImageName ), forState: UIControlState.Highlighted)
        // 自己根据图片的大小来适应
        button.sizeToFit()
        // 便利构造函数需要调用一个当前类的指定构造函数
        self.init(customView: button)
    }
 /// 创建UIBarButtonItem按钮(2张图片)
    class func creatBarButtonItem(imageName: String) -> UIBarButtonItem {
        let highlightedImageName = imageName + "_highlighted"
        // 右边按钮
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: highlightedImageName ), forState: UIControlState.Highlighted)
        // 自己根据图片的大小来适应
        button.sizeToFit()

        return UIBarButtonItem(customView: button)
    }
}
